package me.zhengjie.modules.businessRevoke.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.businessRevoke.service.BusinessRevokeService;
import me.zhengjie.modules.fileupload.domain.dto.ElectronicMaterialFileDetailVOCriteria;
import me.zhengjie.modules.logs.domain.BusinessLog;
import me.zhengjie.modules.transfer.service.TransferOutService;
import me.zhengjie.tool.ValidateUtil;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.Map;

@RestController
@RequiredArgsConstructor
@Api(tags = "api")
@RequestMapping("/api/businessRevoke")
public class BusinessRevokeController {

    @Resource
    private BusinessRevokeService businessRevokeService;

    /**
     * 查询已办业务
     */
    @GetMapping("/list")
    public ResponseEntity<PageResult<BusinessLog>> list(ElectronicMaterialFileDetailVOCriteria criteria){
        ValidateUtil.isEmptyThrowException(criteria.getAae016(),"复核标志");
        Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String, Object> param = objectMapper.convertValue(criteria, Map.class);
        return new ResponseEntity<>(businessRevokeService.queryList(param,page), HttpStatus.OK);
    }


    /**
     * 业务撤销
     */
    @PostMapping("/toRevoke")
    public ResponseEntity<String> toRevoke(@RequestBody Map param) throws IOException {
        ValidateUtil.isEmptyThrowException(param.get("aaz002"),"业务操作日志id");
        ValidateUtil.isEmptyThrowException(param.get("aaa121"),"业务类型");
        businessRevokeService.toRevoke(param);
        return ResponseEntity.ok("成功");
    }
}
